﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using VatTuDTO;
using VatTuBUS1;

namespace CungUngXayDung.admin
{
    public partial class ChiTietNguoiDung : System.Web.UI.Page
    {
        NguoiDungDTO nd= new NguoiDungDTO();
        protected void Page_Load(object sender, EventArgs e)
        {
            LoadDanhSachLoaiNguoiDung();
            string catid = Request.QueryString["catid"].ToString();
            int mand = Convert.ToInt32(catid); 
            nd.MaNguoiDung = mand;
            if (mand != 0)
            {
               
                LayThongTinNguoiDung(mand);
            }

        }
        //Lay THong TIn san Pham theo MaSanPham
        void LayThongTinNguoiDung(int mand)
        {
            nd = new NguoiDungBUS().SelectNguoiDung(mand);
            txtTenNguoiDung.Text = nd.TenNguoiDung.ToString();
            txtGioiTinh.Text = nd.GioiTinh.ToString();

            txtCMND.Text = nd.CMND.ToString();
            txtDiaChi.Text = nd.DiaChi.ToString();
            txtDienThoai.Text = nd.DienThoai.ToString();

            txtEmail.Text = nd.Email.ToString();
            txtTenDangNhap.Text = nd.TenDangNhap.ToString();
            txtMatKhau.Text = nd.MatKhau.ToString();

            ddlLoaiNguoiDung.DataValueField = nd.MaLoaiNguoiDung.ToString();
            Dispose();
        }

        //---------------------------------
        void LoadDanhSachLoaiNguoiDung()
        {
            List<LoaiNguoiDungDTO> lst = new List<LoaiNguoiDungDTO>();
            lst = new LoaiNguoiDungBUS().SelectLoaiNguoiDung();
            ddlLoaiNguoiDung.DataSource = lst;
            ddlLoaiNguoiDung.DataValueField = "MaLoaiNguoiDung";
            ddlLoaiNguoiDung.DataTextField = "TenLoaiNguoiDung";
            ddlLoaiNguoiDung.DataBind();
            Dispose();
        }
        protected void btnCancel_Click(object sender, EventArgs e)
        {
            string url = "QLNguoiDung.aspx";
            Response.Redirect(url);
        }

        //su ly cap nhat lai san pham
        protected void btnSave_Click(object sender, EventArgs e)
        {
            string catid = Request.QueryString["catid"].ToString();
            int dk = Convert.ToInt32(catid);
            if (dk != 0)
            {
                
                nd.TenNguoiDung = Request.Form[2].ToString();
                nd.GioiTinh = Request.Form[3].ToString();
                nd.CMND = Request.Form[4].ToString();
                nd.DiaChi = Request.Form[5].ToString();
                nd.DienThoai = Request.Form[6].ToString();
                nd.Email = Request.Form[7].ToString();
                nd.TenDangNhap = Request.Form[8].ToString();
                nd.MatKhau = Request.Form[9].ToString();
                nd.MaLoaiNguoiDung =int.Parse( Request.Form[10].ToString());

                Boolean n= new NguoiDungBUS().UpdateNguoiDung(nd);
                string url = "QLNguoiDung.aspx";
                Response.Redirect(url);
            }
            if (dk == 0)
            {
                nd.TenNguoiDung = Request.Form[2].ToString();
                nd.GioiTinh = Request.Form[3].ToString();
                nd.CMND = Request.Form[4].ToString();
                nd.DiaChi = Request.Form[5].ToString();
                nd.DienThoai = Request.Form[6].ToString();
                nd.Email = Request.Form[7].ToString();
                nd.TenDangNhap = Request.Form[8].ToString();
                nd.MatKhau = Request.Form[9].ToString();
                nd.MaLoaiNguoiDung = int.Parse(Request.Form[10].ToString());

                new NguoiDungBUS().InsertNguoiDung(nd);
                string url = "QLNguoiDung.aspx";
                Response.Redirect(url);
            }
        }


    }
}